@extends('layouts.app')
@section('content')
    <section class="content-header">
        <h1>
            登山
            <small>奖品编辑</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="/dashboard"><i class="fa fa-dashboard"></i>家</a></li>
            <li><a href="#">登山</a></li>
            <li class="active">奖品编辑</li>
        </ol>

    </section>

    <section class="content-header">

        @if (count($errors) > 0)
            <div class="alert alert-danger alert-dismissible">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <h4><i class="icon fa fa-ban"></i> 错误</h4>
                <ul>
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif
        @if (Session::has('mgssages'))
            <div class="alert alert-success alert-dismissible">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <h4><i class="icon fa fa-check"></i> 状态!</h4>
                <ul>
                    @foreach (Session::get('mgssages') as $message)
                        <li>{{ $message }}</li>
                    @endforeach
                </ul>
            </div>
        @endif
    </section>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">奖品列表</h3>
                        <div class="box-tools">
                        </div>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <div class="tablebox">
                            <form class="form-horizontal" id="form" action="{{route('award.store')}}" method="POST" enctype="multipart/form-data">
                                <input type="hidden" name="id" value="{{$data->id}}">
                                {{csrf_field()}}
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-2 control-label">标题</label>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control name" name="title" disabled
                                               value="{{$data->awardTitle }}" placeholder="标题" maxlength="30" required/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label  class="col-sm-2 control-label">展示图(尺寸140*140)</label>
                                    <div class="col-sm-9">
                                        <input type="file" name="awardPic" @if(!$data->id)required @endif value="{{old('awardPic')}}" >

                                        <img class="pic" data-type="awardPic" src="{{$data->awardPic}}" style="width: 200px;">

                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-2 control-label">奖品数量</label>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control name" name="awardNum"
                                               value="{{$data->awardNum  }}" placeholder="奖品数量" maxlength="30" required onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"/>个
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-2 control-label">获奖数量</label>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control name" name="awardWinNum" disabled
                                               value="{{$data->awardWinNum   }}" placeholder="获奖数量" maxlength="30" required onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"/>个
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-2 control-label">中奖概率</label>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control name" name="awardProbability"
                                               value="{{$data->awardProbability   }}" placeholder="中奖概率" maxlength="3" required onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"/>%
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-10 text-center">
                                        <button class="btn btn-info" type="submit">保存</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                    <!-- /.box-body -->
            </div>
                <!-- /.box -->
        </div>
            <!-- /.col -->
    </div>
        <!-- /.row -->
    </section>
    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">警告</h4>
                </div>
                <div class="modal-body">
                    你确定要下线么？
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <a  class="btn btn-primary active btn-sm model_delete" data-val="" role="button">确定</a>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="releaseModal" tabindex="-1" role="dialog" aria-labelledby="releaseModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="releaseModalLabel">警告</h4>
                </div>
                <div class="modal-body">
                    你确定要发布么？
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <a  class="btn btn-primary active btn-sm" data-val="" role="button">确定</a>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="qrcodeModal" tabindex="-1" role="dialog" aria-labelledby="qrcodeModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="qrcodeModalLabel">活动链接</h4>
                </div>
                <div class="modal-body" style="display: inline-block; width: 100%;">
                    <div style="display: inline-block;text-align: center;border-right: 1px solid #ddd;float: left;" class="col-md-5">
                        <img src="" id="QrCode-img">
                        <div>微信扫一扫</div>
                    </div>
                    <div class="form-horizontal col-md-7" style="display: inline-block;float: left;">
                        <div class="col-md-12 single">
                            <div class="form-group">
                                <div class="col-sm-12">
                                    链接地址
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-12">
                                    <input type="text" class="form-control" name="active-link" id="active-link" value=""/>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-12">
                                    <a  class="btn btn-primary active btn-sm btn-copy" role="button">复制</a>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>
        </div>
    </div>
    <style>
        a{cursor: pointer;}
        .panel{ margin-left: 15px; margin-right: 15px;}

    </style>

    <script>
        $(function(){
            $(".reset").click(function(){
                $(".form-control").val("");
            });
            $(".btn-href").click(function(){
                $("#active-link").val($(this).data("url"));
                $("#QrCode-img").attr('src',$(this).data("qcode"));
            });
            $(".btn-delete").click(function(){
                $("#myModal").find('.modal-footer .btn-primary').attr('href', "/admin/active/del/" + $(this).data("val"));
            });
            $(".btn-release").click(function(){
                $("#releaseModal").find('.modal-footer .btn-primary').attr('href', "/admin/active/release/" + $(this).data("val"));
            });
            $(".btn-copy").on('click',function(){
                var e=document.getElementById("active-link");//对象是content
                e.select(); //选择对象
                document.execCommand("Copy"); //执行浏览器复制命令
                alert("复制成功");
            });
        });
        if($(".alert").css("display","block")){
            setTimeout(function(){
                $(".alert").alert('close');
            }, 3000);
        }
    </script>
@endsection